<?php
$this->pageTitle=Yii::app()->name . ' - Thay đổi thông tin cá nhân';
$this->breadcrumbs = array(
	
);
?>
<div class="well">
	<div class="navbar">
		<div class="navbar-inner"><i class="icon-chevron-right icon-white"></i> Thay đổi thông tin cá nhân</div>
	</div>
	<div class="row-fluid">
		<?php if(Yii::app()->user->hasFlash('success')) {?>
		<div class="alert alert-success"><?php echo Yii::app()->user->getFlash('success')?></div>
		<?php } ?>
		 <?php
    $form=$this->beginWidget('CActiveForm', array(
    'id'=>'user-form',
    'enableAjaxValidation'=>true,
    'htmlOptions'=>array('class'=>'form-horizontal','enctype' => 'multipart/form-data'),
  )); 
    ?>
			<p class="note">Những trường đánh dấu <span class="required">*</span> là trường bắt buộc.</p>
			<?php echo $form->errorSummary(array($model,$profile),"","",array('class'=>'alert alert-error')); ?>
			<fieldset>
	    <legend>Thông tin tài khoản</legend>
		    <div class="control-group">
		      <?php echo $form->labelEx($model,'username',array('class'=>'control-label')); ?>
	        <?php echo $form->textField($model,'username',array('readonly'=>true)); ?>    
		   	</div>
		   	
		  	<p class="note">Bỏ trống mật khẩu nếu không muốn thay đổi.</p>
		  	
		  	<div class="control-group">
					<?php echo $form->labelEx($model,'oldpass',array('class'=>'control-label')); ?>
			    <?php echo $form->passwordField($model,'oldpass',array('autocomplete'=>'off')); ?>
				</div>
		    <div class="control-group">
		      <?php echo $form->labelEx($model,'password',array('class'=>'control-label')); ?>
          <?php echo $form->passwordField($model,'password',array('autocomplete'=>'off')); ?>    
        </div>
		    
		    <div class="control-group">
		    	<?php echo $form->labelEx($model,'repass',array('class'=>'control-label')); ?>
     	    <?php echo $form->passwordField($model,'repass',array('autocomplete'=>'off')); ?>    
	      </div>
	      
	      <div class="control-group">
		      <?php echo $form->labelEx($profile,'email',array('class'=>'control-label')); ?>
          <?php echo $form->textField($profile,'email',array('readonly'=>true))?>    
		   	</div>
	  	</fieldset>
	  	
	  	<fieldset>
	    <legend>Thông tin cá nhân</legend>
		    <div class="control-group">
		      <?php echo $form->labelEx($profile,'fullname',array('class'=>'control-label')); ?>
          <?php echo $form->textField($profile,'fullname',array('autocomplete'=>'off','required'=>'required'))?>    
		   	</div>
		  
		    <div class="control-group">
					<?php echo $form->labelEx($profile,'avatar',array('class'=>'control-label')); ?>
          <?php echo $form->fileField($profile,'avatar')?>
          <div id="img_avatar">
          <?php if (!empty($img_avatar)) {?>
          <a href="javascript: void(0)" onclick="RemoveImage(<?php echo $profile->ID?>)" class="icon-remove"></a>
          <img class="img-polaroid img-rounded" id="avatar" alt="avatar" src="<?php echo $img_avatar?>">
          <?php }?>
          </div>
				</div>
				
		    <div class="control-group">
		      <?php echo $form->labelEx($profile,'dateofbirth',array('class'=>'control-label')); ?>
          <?php echo $form->textField($profile,'dateofbirth', array('readonly'=>'readonly','autocomplete'=>'off','class'=>'datepicker'))?>    
	      </div>
	      
	      <div class="control-group">
		      <?php echo $form->labelEx($profile,'gender',array('class'=>'control-label')); ?>
		      <div class="gender">
		      <?php echo $form->radioButtonList($profile,'gender',array('1'=>'Nam','0'=>'Nữ'), array('separator'=>'',
        		'template'=>'{input}{label}')) ?>
		      </div>	    
		   	</div>
		   	
		   	<div class="control-group">
		      <?php echo $form->labelEx($profile,'phone',array('class'=>'control-label')); ?>
          <?php echo $form->textField($profile,'phone',array('autocomplete'=>'off'))?>    
		   	</div>
		   	
		   	<div class="control-group">
		      <?php echo $form->labelEx($profile,'city',array('class'=>'control-label')); ?>
		       <?php echo $form->dropDownList($profile,'city',$profile->getCity(),array('prompt'=>'Chọn thành phố/tỉnh')); ?>	    
		   	</div>
		   	
		   	<div class="control-group">
		      <?php echo $form->labelEx($profile,'school',array('class'=>'control-label')); ?>
          <?php echo $form->textField($profile,'school',array('autocomplete'=>'off'))?>    
		   	</div>
	  	</fieldset>
			<?php echo CHtml::submitButton('Cập nhật thông tin', array('class'=>'btn btn-success')); ?>
		<?php $this->endWidget(); ?>
	</div>
</div>
<script type="text/javascript">
var d=new Date();
var now = d.getFullYear();
var past = d.getFullYear()-90;
var range = past+":"+now;
$(function() {
	$(window).load(function(){
		$("#img_captcha").trigger("click");
	});
  $(".datepicker").datepicker({
  	dateFormat: 'dd-mm-yy',
    changeMonth: true,
    changeYear: true,
    yearRange: range,
    dayNamesMin: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  });
});
function RemoveImage(id) {
	var notice = '<?php echo "Bạn có chắc muốn xóa hình ảnh này?"?>';
	if(confirm(notice)) {
		$.ajax({
				"url": baseUrl + "/user/removeimage",
        "data":{"ID" : id},
        "type":"post",
        success:function(data){
          if(data=="success") {
          	$('#img_avatar').remove();
          }
        },
        beforeSend: function() {
        	$("#img_avatar").html("");
  			  $("#img_avatar").addClass("load");
  		  }
		});
	}
}
</script>